package com.juyu.miliao.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.juyu.miliao.api.domain.MessageSettings;
import com.juyu.miliao.api.domain.UserMessageSettings;
import com.juyu.miliao.api.domain.vo.MessageVo;
import com.juyu.miliao.api.service.MessageSettingsService;
import com.juyu.miliao.common.domain.Subject;
import com.juyu.miliao.common.exception.ConsumeRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *  通话设置控制层
 * @Auther: 卜加超
 * @Date: 2019/1/16 17:03
 * @Description:
 */
@RestController
@RequestMapping("messageSettings")
public class MessageSettingsController {
    private static final Logger logger = LoggerFactory.getLogger(MessageSettingsController.class);
    @Resource
    private MessageSettingsService messageSettingsService;

    /**
     * 主播获取视频通话列表
     * @param token
     * @return
     */
    @GetMapping("list")
    public List<MessageVo> getMessageSettingList(Authentication token){
        Subject subject = (Subject) token.getPrincipal();
        return messageSettingsService.getHostUserMessageSettingList(subject.getId());
    }
//
//    /**
//     * 通话设置
//     * 展示当前人数 金币 页面
//     * @param
//     * @return
//     */
//    @GetMapping("list/{1")
//    public List<UserMessageSettings> getUserMessageSettingList(Authentication token){
//        Subject subject = (Subject) token.getPrincipal();
//        return  messageSettingsService.getUserMessageSettingsList(subject.getId());
//    }


//    /**
//     * 用户修改当前金币选项
//     */
//    @PatchMapping("/showMessageId")
//    public void updateShowPrice(Authentication token, MessageSettings messageSettings){
//        if(messageSettings.getMessageType()!=1 && messageSettings.getMessageType()!=2)
//            throw new ConsumeRuntimeException("参数错误，更新失败");
//        if(messageSettings.getShowMessageId()<=0)
//            throw new ConsumeRuntimeException("参数错误，更新失败");
//        Subject subject = (Subject) token.getPrincipal();
//        messageSettingsService.updateUserMessageId(subject.getId(),messageSettings.getMessageType(),messageSettings.getShowMessageId());
//    }

    /**
     * 主播端2.0.2修改通话设置
     * @param token
     * @param coinsPerMinute
     */
    @PutMapping("/showMessageId")
    public void userChooseMessageSetting(Authentication token,@RequestParam String coinsPerMinute){
        Subject subject = (Subject) token.getPrincipal();

        messageSettingsService.userChooseMessageSetting(subject.getId(),Integer.parseInt(coinsPerMinute));
    }
}
